//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-//* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */#ifndef nsUrlClassifierStreamUpdater_h_#define nsUrlClassifierStreamUpdater_h_#include<nsISupportsUtils.h>#include"nsCOMPtr.h"#include"nsIObserver.h"#include"nsIUrlClassifierStreamUpdater.h"#include"nsIStreamListener.h"#include"nsIChannel.h"#include"nsTArray.h"#include"nsITimer.h"#include"mozilla/Attributes.h"// Forward declare pointersclassnsIURI;classnsUrlClassifierStreamUpdaterfinal:publicnsIUrlClassifierStreamUpdater,publicnsIUrlClassifierUpdateObserver,publicnsIStreamListener,publicnsIObserver,publicnsIInterfaceRequestor,publicnsITimerCallback{public:nsUrlClassifierStreamUpdater();NS_DECL_THREADSAFE_ISUPPORTSNS_DECL_NSIURLCLASSIFIERSTREAMUPDATERNS_DECL_NSIURLCLASSIFIERUPDATEOBSERVERNS_DECL_NSIINTERFACEREQUESTORNS_DECL_NSIREQUESTOBSERVERNS_DECL_NSISTREAMLISTENERNS_DECL_NSIOBSERVERNS_DECL_NSITIMERCALLBACKprivate:// No subclassing~nsUrlClassifierStreamUpdater(){}// When the dbservice sends an UpdateComplete or UpdateFailure, we call this// to reset the stream updater.voidDownloadDone();// Disallow copy constructornsUrlClassifierStreamUpdater(nsUrlClassifierStreamUpdater&);nsresultAddRequestBody(constnsACString&aRequestBody);// Fetches an update for a single table.nsresultFetchUpdate(nsIURI*aURI,constnsACString&aRequest,boolaIsPostRequest,constnsACString&aTable);// Dumb wrapper so we don't have to create URIs.nsresultFetchUpdate(constnsACString&aURI,constnsACString&aRequest,boolaIsPostRequest,constnsACString&aTable);// Fetches the next table, from mPendingUpdates.nsresultFetchNext();// Fetches the next request, from mPendingRequestsnsresultFetchNextRequest();enumUpdateTimeout{eNoTimeout=0,eResponseTimeout=1,eDownloadTimeout=2,};boolmIsUpdating;boolmInitialized;boolmDownloadError;boolmBeganStream;nsCStringmDownloadErrorStatusStr;// Note that mStreamTable is only used by v2, it is empty for v4 update.nsCStringmStreamTable;nsCOMPtr<nsIChannel>mChannel;nsCOMPtr<nsIUrlClassifierDBService>mDBService;// In v2, a update response might contain redirection and this// timer is for fetching the redirected update.nsCOMPtr<nsITimer>mFetchIndirectUpdatesTimer;// When we DownloadUpdate(), the DBService might be busy on processing// request issused outside of StreamUpdater. We have to fire a timer to// retry on our own.nsCOMPtr<nsITimer>mFetchNextRequestTimer;// Timer to abort the download if the server takes too long to respond.nsCOMPtr<nsITimer>mResponseTimeoutTimer;// Timer to abort the download if it takes too long.nsCOMPtr<nsITimer>mTimeoutTimer;structPendingRequest{nsCStringmTables;nsCStringmRequestPayload;boolmIsPostRequest;nsCStringmUrl;nsCOMPtr<nsIUrlClassifierCallback>mSuccessCallback;nsCOMPtr<nsIUrlClassifierCallback>mUpdateErrorCallback;nsCOMPtr<nsIUrlClassifierCallback>mDownloadErrorCallback;};nsTArray<PendingRequest>mPendingRequests;structPendingUpdate{nsCStringmUrl;nsCStringmTable;};nsTArray<PendingUpdate>mPendingUpdates;nsCOMPtr<nsIUrlClassifierCallback>mSuccessCallback;nsCOMPtr<nsIUrlClassifierCallback>mUpdateErrorCallback;nsCOMPtr<nsIUrlClassifierCallback>mDownloadErrorCallback;// The provider for current update request and should be only used by telemetry// since it would show up as "other" for any other providers.nsCStringmTelemetryProvider;PRIntervalTimemTelemetryClockStart;};#endif // nsUrlClassifierStreamUpdater_h_